import api from './index'

// 用户相关API
export const userApi = {
  // 获取所有用户
  getAllUsers: () => api.get('/users'),
  
  // 根据ID获取用户
  getUserById: (id) => api.get(`/users/${id}`),
  
  // 创建用户
  createUser: (userData) => api.post('/users', userData),
  
  // 更新用户
  updateUser: (id, userData) => api.put(`/users/${id}`, userData),
  
  // 删除用户
  deleteUser: (id) => api.delete(`/users/${id}`),
  
  // 更新用户密码
  updateUserPassword: (id, passwordData) => api.put(`/users/${id}/password`, passwordData),
  
  // 验证用户邮箱
  verifyUserEmail: (id) => api.post(`/users/${id}/verify-email`)
}

// 生理周期相关API
export const menstrualCycleApi = {
  // 获取用户的所有周期记录
  getCyclesByUserId: (userId, startDate, endDate) => {
    const params = { userId }
    if (startDate) params.startDate = startDate
    if (endDate) params.endDate = endDate
    return api.get('/HealthRecords/menstrual-cycle', { params })
  },
  
  // 创建周期记录
  createCycle: (cycleData) => api.post('/HealthRecords/menstrual-cycle', cycleData),
  
  // 获取健康记录
  getHealthRecord: (id) => api.get(`/HealthRecords/${id}`),
  
  // 创建健康记录
  createHealthRecord: (recordData) => api.post('/HealthRecords', recordData),
  
  // 更新健康记录
  updateHealthRecord: (id, recordData) => api.put(`/HealthRecords/${id}`, recordData),
  
  // 删除健康记录
  deleteHealthRecord: (id) => api.delete(`/HealthRecords/${id}`)
}

// 习惯相关API
export const habitApi = {
  // 获取用户的所有习惯
  getHabitsByUserId: (userId, type, isActive) => {
    const params = { userId }
    if (type) params.type = type
    if (isActive !== undefined) params.isActive = isActive
    return api.get('/Habits', { params })
  },
  
  // 根据ID获取习惯
  getHabitById: (id) => api.get(`/Habits/${id}`),
  
  // 创建习惯
  createHabit: (habitData) => api.post('/Habits', habitData),
  
  // 更新习惯
  updateHabit: (id, habitData) => api.put(`/Habits/${id}`, habitData),
  
  // 激活习惯
  activateHabit: (id) => api.post(`/Habits/${id}/activate`),
  
  // 停用习惯
  deactivateHabit: (id) => api.post(`/Habits/${id}/deactivate`),
  
  // 删除习惯
  deleteHabit: (id) => api.delete(`/Habits/${id}`),
  
  // 获取护肤习惯
  getSkincareHabits: (userId) => {
    const params = { userId }
    return api.get('/Habits/skincare', { params })
  },
  
  // 创建护肤习惯
  createSkincareHabit: (habitData) => api.post('/Habits/skincare', habitData)
}

// 护肤相关API
export const skincareApi = {
  // 获取用户的所有护肤记录
  getSkincareByUserId: (userId, date) => {
    const params = { userId }
    if (date) params.date = date
    return api.get('/HabitRecords/skincare', { params })
  },
  
  // 创建护肤记录
  createSkincare: (skincareData) => api.post('/HabitRecords/skincare', skincareData),
  
  // 获取习惯记录
  getHabitRecord: (id) => api.get(`/HabitRecords/${id}`),
  
  // 创建习惯记录
  createHabitRecord: (recordData) => api.post('/HabitRecords', recordData),
  
  // 标记习惯记录为已完成
  markHabitRecordAsCompleted: (id) => api.post(`/HabitRecords/${id}/complete`),
  
  // 标记习惯记录为未完成
  markHabitRecordAsIncompleted: (id) => api.post(`/HabitRecords/${id}/incomplete`),
  
  // 更新习惯记录备注
  updateHabitRecordNotes: (id, notesData) => api.put(`/HabitRecords/${id}/notes`, notesData),
  
  // 删除习惯记录
  deleteHabitRecord: (id) => api.delete(`/HabitRecords/${id}`)
}

// 隐私设置相关API
export const privacyApi = {
  // 获取用户隐私设置（模拟接口）
  getPrivacyByUserId: (userId) => {
    // 由于后端没有专门的隐私控制器，这里返回模拟数据
    return Promise.resolve({
      userId,
      dataCategories: [
        { name: '生理周期', level: 2 },
        { name: '习惯打卡', level: 1 },
        { name: '护肤记录', level: 2 },
        { name: '个人日记', level: 3 },
        { name: '个人资料', level: 1 }
      ],
      securitySettings: {
        biometricEnabled: true,
        dataEncryption: true,
        autoLockTime: 5
      }
    })
  },
  
  // 更新隐私设置（模拟接口）
  updatePrivacySettings: (userId, settings) => {
    // 由于后端没有专门的隐私控制器，这里返回模拟成功响应
    return Promise.resolve({ success: true, message: '隐私设置更新成功' })
  },
  
  // 创建隐私设置（模拟接口）
  createPrivacy: (privacyData) => {
    // 由于后端没有专门的隐私控制器，这里返回模拟成功响应
    return Promise.resolve({ 
      id: '00000000-0000-0000-0000-000000000000',
      ...privacyData,
      createdOn: new Date().toISOString()
    })
  },
  
  // 导出用户数据（模拟接口）
  exportUserData: (userId) => {
    // 由于后端没有专门的隐私控制器，这里返回模拟数据
    return Promise.resolve({
      userId,
      exportDate: new Date().toISOString(),
      data: {
        user: {},
        healthRecords: [],
        habits: [],
        habitRecords: []
      }
    })
  },
  
  // 删除用户数据（模拟接口）
  deleteUserData: (userId) => {
    // 由于后端没有专门的隐私控制器，这里返回模拟成功响应
    return Promise.resolve({ success: true, message: '用户数据删除成功' })
  }
}

export default {
  userApi,
  menstrualCycleApi,
  habitApi,
  skincareApi,
  privacyApi
}